Reports and manuscripts with Quarto

What is quarto?

  • Open-source document format and computational notebook system
  • Integrates text, code, and outout
  • Can create multiple different types of products (documents, slides, websites, books)

Why not R Markdown?

Only because quarto is newer and more featured!

  • Anything you already know how to do in R Markdown you can do in quarto, and more!
  • All of these slides, website, etc. are all made in quarto.
  • If you know and love R Markdown, by all means keep using it!

Quarto workflow

  1. Create a Quarto document
  2. Write code
  3. Write text
  4. Repeat 2-3 in whatever order you want
  5. Render repeatedly as you go

How does it work?

  • You text in markdown and code in R
  • knitr processes the code chunks, executes the R code, and inserts the code outputs (e.g., plots, tables) back into the markdown document
  • pandoc transforms the markdown document into various output formats

Text and code…

# My header

Some text

Some *italic text*

Some **bold text**

- Eggs
- Milk

```{r}
x <- 3
x
```

… becomes …

My title

Some text

Some italic text

Some bold text

  • Eggs
  • Milk
x <- 3
x
[1] 3

If you prefer, you can use the visual editor

R chunks

Everything within the chunks has to be valid R1

```{r}
x <- 3
```
```{r}
x + 4
```
[1] 7

Chunks run in order, continuously, like a single script

YAML

At the top of your Quarto document, a header written in yaml describes options for the document

---
title: "My document"
author: Louisa Smith
format: html
---

There are a ton of possible options, but importantly, this determines the document output

Output

https://quarto.org/docs/output-formats/all-formats.html

Exercises

We’re going to focus on html output

  • It’s easy to transition to Word (format: docx) but it’s not as good for constant re-rendering
  • You need a LaTeX installation for pdf (format: pdf)

Exercises

You can choose whether you want to have chunk output show up within the document (vs. just the console) when you are running Quarto (and RMarkdown) documents interactively

Tools > Global options

Exercises

Open up your epi590r-2023-in-class R project!

File > New File > Quarto Document

Exercises

  • Try toggling between Source and Visual views
  • Toggle on and off the Outline
  • Click Render and look at the output